﻿#include "lua_obj.h"

static int lua_lv_style_reset(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_register_prop(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_remove_prop(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_set_prop(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_get_prop(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_get_prop_inlined(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_transition_dsc_init(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);
    uint32_t time = luaL_checkinteger(L, 4);
    uint32_t delay = luaL_checkinteger(L, 5);

    return 0;
}

static int lua_lv_style_prop_get_default(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_is_empty(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua__lv_style_get_prop_group(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);
    uint16_t res = _lv_style_get_prop_group(a);
    lua_pushinteger(L, res);

    return 1;
}

static int lua_lv_style_set_size(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_set_pad_all(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_set_pad_hor(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_set_pad_ver(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_lv_style_set_pad_gap(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_while(lua_State *L)
{
    LUA_USER_DEBUG(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);

    return 0;
}

static int lua_auto_gc(lua_State *L)
{
    lv_obj_t *lv_obj = *(lv_obj_t **)luaL_checkudata(L, 1, META_STYLE);
    luaL_argcheck(L, lv_obj != NULL, 1, "invalid user data");
    if (lv_obj)
    {
        lv_obj_del(lv_obj);
    }
    return 0;
}
static const struct luaL_Reg arraylib_m[] = {
    {"init", lua_lv_style_init},
    {"reset", lua_lv_style_reset},
    {"register_prop", lua_lv_style_register_prop},
    {"remove_prop", lua_lv_style_remove_prop},
    {"set_prop", lua_lv_style_set_prop},
    {"get_prop", lua_lv_style_get_prop},
    {"get_prop_inlined", lua_lv_style_get_prop_inlined},
    {"transition_dsc_init", lua_lv_style_transition_dsc_init},
    {"prop_get_default", lua_lv_style_prop_get_default},
    {"is_empty", lua_lv_style_is_empty},
    {"_get_prop_group", lua__lv_style_get_prop_group},
    {"set_size", lua_lv_style_set_size},
    {"set_pad_all", lua_lv_style_set_pad_all},
    {"set_pad_hor", lua_lv_style_set_pad_hor},
    {"set_pad_ver", lua_lv_style_set_pad_ver},
    {"set_pad_gap", lua_lv_style_set_pad_gap},
    {"while", lua_while},
    LUA_LV_OBJ_RLT,
    {NULL, NULL}};

static char str[][20] = {
    "lv_style_t * style, lv_style_prop_t prop",
    "lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value",
    "lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value",
    "lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value",
    "lv_style_transition_dsc_t * tr, const lv_style_prop_t props[],
                                  lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data",
    "lv_style_t * style, lv_coord_t value",
    "lv_style_t * style, lv_coord_t value",
    "lv_style_t * style, lv_coord_t value",
    "lv_style_t * style, lv_coord_t value",
    "lv_style_t * style, lv_coord_t value",
};

static int help(lua_State *L)
{
    uint16_t n = sizeof(arraylib_m) / sizeof(struct luaL_Reg);
    for (int i = 0; i < n - 1; i++)
    {
        printf("%s\n", arraylib_m[i].name);
    }
    return 1;
}

static const struct luaL_Reg arraylib_f[] = {
    {"help", help},
    {NULL, NULL}};

LUALIB_API int lua_lv_style_funinit(lua_State *L)
{
    luaL_newlib(L, arraylib_f);
    luaL_newmetatable(L, META_STYLE);  /* create metatable for file handles */
    lua_pushvalue(L, -1);            /* push metatable */
    lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
    luaL_setfuncs(L, arraylib_m, 0); /* add file methods to new metatable */
    lua_pop(L, 1);                   /* pop new metatable */

    return 1;
}